package com.wan37.client.message.received;

import com.google.protobuf.Message;
import com.googlecode.protobuf.format.JsonFormat;
import com.wan37.client.service.cache.UserServiceCache;
import com.wan37.protobuf.constant.PtoNum;
import com.wan37.protobuf.message.client2server.game.GameEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author : luoyong
 * @date : 2020-08-01 16:13
 **/
@Component(PtoNum.USER + "")
public class UserResponse implements ReceiveMsg{
    private final Logger logger = LoggerFactory.getLogger(UserResponse.class);
    @Autowired
    private UserServiceCache userServiceCache;

    @Override
    public void execute(Message msg) {
        GameEntity.User user = (GameEntity.User) msg;
        userServiceCache.getUserInMap().get(user.getUserId()).setUser(user);
        logger.info("用户状态更新：{}", JsonFormat.printToString(user));
    }
}
